package com.xianyu.us.pojo.vo;

import java.io.Serializable;

/**
 * 封装视图层返回的json信息，包含状态、msg、和数据
 * @author wangshili
 *
 */
public class JsonResult  implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6035804478622444325L;
	//状态码
	private Integer state = 1;//1表示成功，0表示失败
	//状态信息
	private String message = "ok";//默认是ok
	//数据
	private Object data;//这个要传给前端的数据跟前端获取的命名必须一致
	
	public JsonResult() { 
		//也可以通过无参构造来进行初始化
		this.state=1;
		this.message="ok";
	}
	
	public JsonResult(String msg) {
		this.message=msg;
	}
	
	//封装数据
	public JsonResult(Object data) {
		this.data=data;
	}
	
	//异常处理
	public JsonResult(Throwable t) {
		this.state=0;
		this.message = t.getMessage();
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "JsonResult [state=" + 
				state + ", message=" + message + ", data=" + data + "]";
	}
	
	
}
